{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from osgeo import gdal\n",
    "import numpy as np\n",
    "from osgeo import osr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "projection: PROJCS[\"WGS 84 / UTM zone 47N\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",99],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH],AUTHORITY[\"EPSG\",\"32647\"]]\n",
      "geo_trans: (800000.0, 10.0, 0.0, 2800000.0, 0.0, -10.0)\n",
      "800000.0 909760.0 2800000.0 2690240.0\n"
     ]
    }
   ],
   "source": [
    "path_img=\"D:\\Lenovo\\Desktop\\云南大学\\开源地理信息系统\\output\\subset_0_of_S2A_MSIL2A_20200411T033531_N0214_R061_T47RRH_20200411T073513.tif\"\n",
    "path_resam=\"D:\\Lenovo\\Desktop\\云南大学\\开源地理信息系统\\output\\subset_resam.tif\"\n",
    "dset=gdal.Open(path_img)\n",
    "proj=dset.GetProjection()\n",
    "print('projection:',proj)\n",
    "geo_trans=dset.GetGeoTransform()\n",
    "print('geo_trans:',geo_trans)\n",
    "x_min=geo_trans[0]\n",
    "x_max=geo_trans[0]+geo_trans[1]*dset.RasterXSize\n",
    "y_min=geo_trans[3]\n",
    "y_max=geo_trans[3]+geo_trans[5]*dset.RasterYSize\n",
    "print(x_min,x_max,y_min,y_max)\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_mean=(x_min+x_max)/2\n",
    "print(x_mean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "wgs84_epsg=4326\n",
    "utm48_epsg=32648\n",
    "wgs84=osr.SpatialReference();wgs84.ImportFromEPSG(wgs84_epsg)\n",
    "utm48=osr.SpatialReference();utm48.ImportFromEPSG(utm48_epsg)\n",
    "transform=osr.CoordinateTransformation(wgs84,utm48)\n",
    "print(geo_trans[0],geo_trans[3])\n",
    "(x_min_utm,y_max_utm,z)=transform.TransformPoint(geo_trans[3],geo_trans[0],0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver=gdal.GetDriverByName('GTiff')\n",
    "dest_resam=driver.Create(path_resam,xsize=?,ysize=?,bands=dest.RasterCount,eType=gdal.GDT_Byte)\n",
    "dest_resam.SetProjection(dset.GetProjection())\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
